all files / src/helpers/ game.helpers.ts

88.89% Statements 8/9
100% Branches 0/0
100% Functions 3/3
88.89% Lines 8/9
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18    10×                
import { Game, Phase } from '../game.interfaces';
import { Base64 } from 'js-base64';
 
export function isBomb(pointsValue: number|null): boolean {
    return pointsValue === null;
}
 
export function loadStateFromText(text: string): Game {
    try {
        return JSON.parse(Base64.decode(text));
    } catch(e) { }
    return null;
}
 
export function saveStateToText(state: Game): string {
    return Base64.encode(JSON.stringify(state));
}